<template>
	<view v-show="show">
		<view class="search_school">
			<u-search placeholder="请输入学校名称" v-model="query.schoolName" borderColor="#fff" height="50"
				@custom="findSchoolsByAreaCode" @search="findSchoolsByAreaCode"></u-search>
		</view>
		<view class="state-type">
			<uni-data-select v-model="query.executiveType" :clear="false" placeholder="请选择学段"
				:localdata="executiveTypeList" @change="findSchoolsByAreaCode"></uni-data-select>
		</view>
		<view class="mode-type">
			<uni-data-select v-model="query.type" :clear="false" placeholder="请选择形式" :localdata="typeData"
				@change="findSchoolsByAreaCode"></uni-data-select>
		</view>
		<view class="">
			<u-list>
				<u-list-item v-for="(item, index) in schoolList" :key="index" class="school-item">
					<u-cell :title="item.name" @click="viewRecords(item)">
					</u-cell>
				</u-list-item>
			</u-list>
		</view>
	</view>
</template>

<script>
	import {
		findSchoolsByAreaCode
	} from "../../../api/supervise/index.js"
	export default {
		data() {
			return {
				query: {
					code: 0,
					activityId: 0,
					type: -1,
					executiveType: -1,
					schoolName: ''
				},
				show: true,
				schoolName: "",
				typeData: [{
						value: -1,
						text: "不限"
					},
					{
						value: 0,
						text: "民办"
					}, {
						value: 1,
						text: "公办"
					}
				],
				indexList: ["南明小学", "南明中学", "南明大学"],
				schoolList: [],
				executiveTypeList: []
			}
		},
		onLoad(option) {
			if (Object.keys(option).length > 0) {
				this.query = uni.$u.deepMerge(this.query, option);
				this.findSchoolsByAreaCode();
			}

		},
		methods: {
			viewRecords(item) {
				const queryData = {
					activityId: this.query.activityId,
					schoolId: item.schoolId,
					schoolName: item.name
				}
				this.$tab.navigateTo("/pages/index/supervise/supervise-target?queryData=" + encodeURIComponent(JSON
					.stringify(queryData)));
			},
			findSchoolsByAreaCode() {
				uni.showLoading({
					title: "数据加载中"
				})
				findSchoolsByAreaCode(this.query).then(res => {
					this.executiveTypeList = res.executiveType.map(item => {
						return {
							value: item.id,
							text: item.name
						};

					});
					this.schoolList = res.schools;
					setTimeout(() => {
						this.show = true;
						uni.hideLoading()
					}, 1000)
				}).catch(() => {
					uni.hideLoading()
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.search_school {
		padding: 10px 10px;
	}

	.state-type {
		height: 8vh;
		line-height: 8vh;
	}

	.mode-type {
		height: 8vh;
		line-height: 8vh;
	}

	.school-item {
		text-align: center;
	}
</style>